package com.mingtu.guards.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.lxj.xpopup.core.BasePopupView;
import com.mingtu.center.activity.AuthSetActivity;
import com.mingtu.center.activity.InfoActivity;
import com.mingtu.center.activity.MyOffLineMapActivity;
import com.mingtu.common.base.BaseFragment;
import com.mingtu.common.utils.GridSpacingItemDecoration;
import com.mingtu.common.utils.IntentUtils;
import com.mingtu.common.utils.SPTools;
import com.mingtu.common.utils.StatusBarUtil;
import com.mingtu.common.viewpager.LazyViewPager.LazyFragmentPagerAdapter;
import com.mingtu.guards.R;
import com.mingtu.guards.activity.MyRecordActivity;
import com.mingtu.guards.activity.MySetActivity;
import com.mingtu.guards.activity.TbsWebActivity;
import com.mingtu.guards.adapter.CenterDataAdapter;
import com.mingtu.ocr.activity.MyRecActivity;
import com.mingtu.guards.utils.MyConstant;

import butterknife.BindView;
import butterknife.OnClick;

import static com.mingtu.guards.utils.MyConstant.ItemDecorationSpaces;

public class MineFragment extends BaseFragment implements LazyFragmentPagerAdapter.Laziable {

    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.layout_top)
    FrameLayout layoutTop;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.tv_account_set)
    TextView tvAccountSet;
    private String name;
    private BasePopupView popupView;

//    private UserInfoBean.UserBean userBean;

    @Override
    protected int getLayoutId() {
        return R.layout.mine_fragment;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView(View view) {
        int statusBarHeight = StatusBarUtil.getStatusBarHeight(context);
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) tvTitle.getLayoutParams();
        lp.setMargins(0, statusBarHeight, 0, 0);
        tvTitle.setLayoutParams(lp);

        FrameLayout.LayoutParams lp2 = (FrameLayout.LayoutParams) tvAccountSet.getLayoutParams();
        lp2.setMargins(0, statusBarHeight + SizeUtils.dp2px(30), 0, 0);
        tvAccountSet.setLayoutParams(lp2);


        CenterDataAdapter centerDataAdapter = new CenterDataAdapter(context);
        GridLayoutManager layoutManager = new GridLayoutManager(context, 3);//第二个参数为网格的列数
        recycler.addItemDecoration(new GridSpacingItemDecoration(3, SizeUtils.dp2px(ItemDecorationSpaces), true));
//        recycler.setHasFixedSize(true);
        recycler.setLayoutManager(layoutManager);
        recycler.setAdapter(centerDataAdapter);
        centerDataAdapter.setOnItemClickListener(new CenterDataAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Bundle bundle = new Bundle();
                switch (position) {
                    case 0:
                        //巡护记录
                        bundle.putInt("navPositon", 0);
                        IntentUtils.getInstance().readyGo(getActivity(), MyRecordActivity.class, bundle);
                        break;
                    case 1:
                        //离线地图
                        IntentUtils.getInstance().readyGo(getActivity(), MyOffLineMapActivity.class);
                        break;
                    case 2:
                        //权限设置
                        IntentUtils.getInstance().readyGo(getActivity(), AuthSetActivity.class);
                        break;
                }

            }
        });
    }

    @Override
    protected void getData() {
        name = SPStaticUtils.getString(SPTools.userName);
        if (!StringUtils.isEmpty(name)) {
            tvName.setText(name);
        }
    }


    @OnClick({R.id.layout_top, R.id.tv_account_set})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_top:
                //用户信息
                String mobile = SPStaticUtils.getString(SPTools.mobile);//联系方式
                String roleName = SPStaticUtils.getString(SPTools.roleName);
                String deptName = SPStaticUtils.getString(SPTools.deptName);

                Bundle bundle = new Bundle();
                bundle.putString("name", name);
                bundle.putString("mobile", mobile);
                bundle.putString("roleName", roleName);
                bundle.putString("deptName", deptName);
                IntentUtils.getInstance().readyGo(getActivity(), InfoActivity.class, bundle);
                break;

            case R.id.tv_account_set:
                //账号设置
                IntentUtils.getInstance().readyGo(getActivity(), MySetActivity.class);
                break;
        }
    }


}